<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AnswerInController extends Controller
{	
	// 问题回复
    public function getIndex(Request $request){
       $id=$request->input('id');
       $data=DB::table('issue')
       ->leftjoin('topic','topic.id','=','issue.tid')
       ->select('topic.title','issue.*')
       ->where('issue.id','=',$id)
       ->get();
       // dd($data);

       $id=$data[0]->id;
       // dd($id);

       $date=DB::table('answer')
          ->leftjoin('userdetails','userdetails.uid','=','answer.uid')
       		->where('answer.Iid','=',$id)
       		->get();
       		// dd($date);
       
       return view('home.answer.answerIn',['data'=>$data,'date'=>$date,'id'=>$id]);
       
    }

    // 问题回复添加数据
    public function postInsert(Request $request){
    
    	$id=$request->input('id');
    	$text=$request->input('text');
    	$uid=$request->input('uid');
    	$time=time();
    	// dd($uid);
    	

     
  
      

    	$res=DB::table('answer')->insertGetId(
    		['Iid'=>$id,'content'=>$text,'time'=>$time,'uid'=>$uid]
    	);

    	 
       // dd($id);
    	// dd($res);
    	$data=DB::table('issue')
       ->leftjoin('topic','topic.id','=','issue.tid')
       ->select('topic.title','issue.*')
       ->where('issue.id','=',$id)
       ->get();
		
		$id=$data[0]->id;
       $date=DB::table('answer')
          ->leftjoin('userdetails','userdetails.uid','=','answer.uid')
       		->where('answer.Iid','=',$id)
       		->get();
       		// dd($date)
       		
       // dd($data);
    	return view('home.answer.answerIn',['data'=>$data,'date'=>$date,'id'=>$id]);
    }
    

  
}
